#include <gtest/gtest.h>
#include "common.h"
#include <unordered_map>

using namespace ::std;

class Solution {
public:
    bool isAnagram(string s, string t);
};

bool Solution::isAnagram(string s, string t) {
    if(s.size() != t.size()) return false;
    unordered_map<char, int> seenCnt;
    for(auto c : s) {
        if(seenCnt.find(c) == seenCnt.end()) seenCnt[c] = 1;
            // seenCnt.insert(pair<char, int>(c, 1));
            // seenCnt.insert(map<char, int>::value_type(c, 1));
        else seenCnt[c]++;
    }
    for(auto c : t) {
        if(seenCnt.find(c) == seenCnt.end()) return false;
        else seenCnt[c]--;
        if(-1 == seenCnt[c]) return false;
    }
    return true;
}

class IsAnagramCheck : public ::testing::Test {
public:
	class Solution solution;
};

TEST_F(IsAnagramCheck, testIsAnagram_1) {
    string s("anagram"), t("nagaram");
    EXPECT_TRUE(true == solution.isAnagram(s, t));
}

TEST_F(IsAnagramCheck, testIsAnagram_2) {
    string s("rat"), t("car");
    EXPECT_TRUE(false == solution.isAnagram(s, t));
}

int main() {
	::testing::InitGoogleTest();
	return RUN_ALL_TESTS();
}
